package com.ruoyi.customer.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.customer.domain.vo.TCustomerInfoChangeDetailVo;
import com.ruoyi.customer.domain.bo.TCustomerInfoChangeDetailBo;
import com.ruoyi.customer.service.ITCustomerInfoChangeDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息变更记录
 *
 * @author ruoyi
 * @date 2023-12-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/customer/customerInfoChangeDetail")
public class TCustomerInfoChangeDetailController extends BaseController {

    private final ITCustomerInfoChangeDetailService iTCustomerInfoChangeDetailService;

    /**
     * 查询客户信息变更记录列表
     */
    //@SaCheckPermission("customer:customerInfoChange:list")
    @GetMapping("/list")
    public TableDataInfo<TCustomerInfoChangeDetailVo> list(TCustomerInfoChangeDetailBo bo, PageQuery pageQuery) {
        return iTCustomerInfoChangeDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客户信息变更记录列表
     */
    //@SaCheckPermission("customer:customerInfoChange:export")
    @Log(title = "客户信息变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TCustomerInfoChangeDetailBo bo, HttpServletResponse response) {
        List<TCustomerInfoChangeDetailVo> list = iTCustomerInfoChangeDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "客户信息变更记录", TCustomerInfoChangeDetailVo.class, response);
    }

    /**
     * 信息变更查询
     */
    //@SaCheckPermission("customer:customerInfoChange:export")
    @Log(title = "客户信息变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/nolist")
    public R<List<TCustomerInfoChangeDetailVo>> nolist(TCustomerInfoChangeDetailBo bo) {
        return R.ok(iTCustomerInfoChangeDetailService.queryList(bo));
    }

    /**
     * 获取客户信息变更记录详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("customer:customerInfoChange:query")
    @GetMapping("/{id}")
    public R<TCustomerInfoChangeDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iTCustomerInfoChangeDetailService.queryById(id));
    }

    /**
     * 新增客户信息变更记录
     */
    //@SaCheckPermission("customer:customerInfoChange:add")
    @Log(title = "客户信息变更记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TCustomerInfoChangeDetailBo bo) {
        return toAjax(iTCustomerInfoChangeDetailService.insertByBo(bo));
    }

    /**
     * 修改客户信息变更记录
     */
    //@SaCheckPermission("customer:customerInfoChange:edit")
    @Log(title = "客户信息变更记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TCustomerInfoChangeDetailBo bo) {
        return toAjax(iTCustomerInfoChangeDetailService.updateByBo(bo));
    }

    /**
     * 删除客户信息变更记录
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("customer:customerInfoChange:remove")
    @Log(title = "客户信息变更记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTCustomerInfoChangeDetailService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
